package models

import (
	"time"

	"game-simple/internal/framework/auth/dto"
	"gorm.io/gorm"
)

// UserModel 用户模型
type UserModel struct {
	ID        uint           `gorm:"primarykey" json:"id"`
	Username  string         `gorm:"type:varchar(50);uniqueIndex;not null" json:"username"`
	Email     string         `gorm:"type:varchar(100);uniqueIndex;not null" json:"email"`
	Password  string         `gorm:"type:varchar(255);not null" json:"-"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

func (UserModel) TableName() string {
	return "users"
}

// ToUserResponse 转换为用户响应 DTO
func (m *UserModel) ToUserResponse() dto.UserResponse {
	return dto.UserResponse{
		ID:        m.ID,
		Username:  m.Username,
		Email:     m.Email,
		CreatedAt: m.CreatedAt.Format(time.RFC3339),
		UpdatedAt: m.UpdatedAt.Format(time.RFC3339),
	}
}

